package ch.ethz.fcl.metrobuzz.controller.gui.swing;

import java.awt.*;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import net.miginfocom.swing.MigLayout;

import ch.ethz.fcl.metrobuzz.render.MBRenderer;

public class ColorPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	JSlider r;
	JSlider g;
	JSlider b;
	JSlider a;

	public ColorPanel(MBRenderer render) {
		super(new MigLayout());
		JLabel r_label = new JLabel("Red");
		JLabel g_label = new JLabel("Green");
		JLabel b_label = new JLabel("Blue");
		JLabel a_label = new JLabel("Alpha");

		setBackground(Color.lightGray);
		setBorder(BorderFactory.createTitledBorder("Color"));

		r = new JSlider(JSlider.HORIZONTAL, 0, 100, 100);
		r.createStandardLabels(1);
		r.setMajorTickSpacing(20);
		r.setMinorTickSpacing(2);
		r.setPaintTicks(true);
		r.setPaintLabels(true);
		r.addChangeListener(new ColorListener());

		g = new JSlider(JSlider.HORIZONTAL, 0, 100, 100);
		g.createStandardLabels(1);
		g.setMajorTickSpacing(20);
		g.setMinorTickSpacing(2);
		g.setPaintTicks(true);
		g.setPaintLabels(true);
		g.addChangeListener(new ColorListener());

		b = new JSlider(JSlider.HORIZONTAL, 0, 100, 100);
		b.createStandardLabels(1);
		b.setMajorTickSpacing(20);
		b.setMinorTickSpacing(2);
		b.setPaintTicks(true);
		b.setPaintLabels(true);
		b.addChangeListener(new ColorListener());

		a = new JSlider(JSlider.HORIZONTAL, 0, 100, 100);
		a.createStandardLabels(1);
		a.setMajorTickSpacing(20);
		a.setMinorTickSpacing(2);
		a.setPaintTicks(true);
		a.setPaintLabels(true);
		a.addChangeListener(new ColorListener());

		add(r_label);
		add(r, "span, grow");
		add(g_label);
		add(g, "span, grow");
		add(b_label);
		add(b, "span, grow");
		add(a_label);
		add(a, "span, grow");
	}

	class ColorListener implements ChangeListener {
		@Override
		public void stateChanged(ChangeEvent changeEvent) {
			// Object source = changeEvent.getSource();
			// if (source instanceof JSlider) {
			// JSlider slider = (JSlider) source;
			// if (!slider.getValueIsAdjusting()) {
			// // if (slider.equals(r)) {
			// //// RoadRender.RRATIO = slider.getValue();
			// //// } else if (slider.equals(g)) {
			// //// RoadRender.GRATIO = slider.getValue();
			// //// } else if (slider.equals(b)) {
			// //// RoadRender.BRATIO = slider.getValue();
			// //// } else if (slider.equals(a)) {
			// //// RoadRender.ARATIO = slider.getValue();
			// //// }
			// //// ResultRenderer.UPDATE = true;
			// // }
			// }
		}
	}
}